//
// Created by ta&to on 2022/8/29.
//
#include "http_alloc.h"
void *http_malloc(size_t size)
{
    void *p = malloc(size);
    if (p == NULL) {
        printf("malloc(%zu) failed", size);
    }
    return p;
}

void * http_calloc(size_t size)
{
    void *p;
    p = http_malloc(size);
    if(p)
    {
        memset(p, 0, size);
    }
    return p;
}

void * http_realloc(char* p, size_t size)
{
    return realloc(p, size);
}
int mallen(char* p)
{
    if(p) {
        return malloc_usable_size(p);
    }
    return 0;
}
// 补齐
int http_malloc_align(int size)
{
#if (LONG_MAX == LLONG_MAX)
    int ALIGN = 16;             //对齐位数
#else
    int ALIGN = 8;
#endif
    return (size/ALIGN * ALIGN) + (size%ALIGN>0?ALIGN:0);
}
void http_free(void *f) {
    if(ISNULL(f))return;
    free(f);
    f = NULL;
}
void http_free_null(void **f) {
   free(*f);
   *f = NULL;
}